"use server";
import "./index.css";
import Title from "antd/es/typography/Title";
import { Flex, message } from "antd";
import {
  listQuestionVoByPageUsingPost,
  searchQuestionVoByPageUsingPost,
} from "@/api/questionController";
import QuestionTable from "@/app/components/QuestionTable";

/**
 * 题库列表页
 * @constructor
 */
// @ts-ignore
export default async function QuestionsPage({ searchParams }) {
  // 获取url的查询条件
  const { q: searchText } = searchParams;
  let questionList = [];
  let total = 0;

  try {
    const res = await searchQuestionVoByPageUsingPost({
      searchText: searchText,
      pageSize: 12,
      sortField: "createTime",
      sortOrder: "descend",
    });
    // @ts-ignore
    questionList = res.data.records ?? [];
    // @ts-ignore
    total = res.data.total ?? 0;
  } catch (e) {
    // @ts-ignore
    message.error("获取题目列表失败" + e.message);
  }

  return (
    <div id={"QuestionsPage"} className={"max-width-content"}>
      <Flex justify={"space-between"} align={"center"}>
        <Title level={3}>题目大全</Title>
      </Flex>
      {/*@ts-ignore*/}
      <QuestionTable defaultQuestionList={questionList} defaultTotal={total} defaultSearchParams={{
        title: searchText,
      }} />
    </div>
  );
}
